jQuery(function() {
	var window_width = $(window).width();
	jQuery('#element_0').width(window_width);
	jQuery('body').css('width',window_width);
});

function offset(item) {
	var leftPosition = jQuery(item).position().left;
	jQuery(item).offset({top:0,left:leftPosition});
}

function nextDiv(position) {
	// reset
	reset();
	// show specific content
	var selector = "div[id=element_"+position+"]";
	var itemwidth = $(window).width();
	jQuery("div[id^=element]").css('width',itemwidth);
	jQuery(selector).css('display','inline-block');

	// Update body size
	jQuery('body').css('width',itemwidth*2);
	//Scroll to the div
	jQuery('html, body').animate({scrollLeft: itemwidth,scrollTop: 0},800);
	console.log("Position "+position);
	if(position === 2) {
		loadCarousel();
	}
	if(position === 4) {
		loadColorBox();
	}
}

function firstDiv() {
	// Scroll to the top left
	var leftPosition = 0;
	jQuery('html, body').animate({scrollLeft: leftPosition,scrollTop: 0},800,function() {reset();});
}

function reset() {
	
	jQuery("div[id^=element]").each(function(i) {
		if($(this).attr('id') !== 'element_0') {
			$(this).css('display','none');
			$(this).css('width',0);
		}
	});
	$('body').width($(window).width());
}

function loadColorBox() {
	console.log('Loading color box');
	$('a.gallery').colorbox({rel:'gal'});
}